import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from cashbonus.models import *


class CashActivityFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_state = django_filters.BaseInFilter(field_name='activity_state', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')
    available_time_begin = django_filters.DateTimeFilter(field_name="available_begin_time__date", lookup_expr='gte')
    available_time_end = django_filters.DateTimeFilter(field_name="available_end_time__date", lookup_expr='lte')

    class Meta:
        model = CashActivity
        fields = ('activity_state', 'activity_type', 'available_time_begin', 'available_time_end')


class CashActivityWhiteTableFilter(django_filters.rest_framework.FilterSet):

    cashactivity_id = django_filters.BaseInFilter(field_name='cashactivity_id', lookup_expr='in')
    is_admin = django_filters.BaseInFilter(field_name='is_admin', lookup_expr='in')

    class Meta:
        model = CashActivityWhiteTable
        fields = ('cashactivity_id', 'is_admin')


class CashActivityLevelFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_id = django_filters.BaseInFilter(field_name='cash_activity_id', lookup_expr='in')
    dimensionality = django_filters.BaseInFilter(field_name='level__level', lookup_expr='in')

    class Meta:
        model = CashActivityLevel
        fields = ('activity_id', 'dimensionality')


class CashActivityDataFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    # cash_activity_level_id = django_filters.BaseInFilter(field_name='cash_activity_level_id', lookup_expr='in')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    level_id = django_filters.BaseInFilter(field_name='level_id', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='cash_activity_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = CashActivityData
        fields = ('state', 'level_id', 'activity_id', 'create_time_begin', 'create_time_end')


class CashActivityDataKeguanFilter(django_filters.rest_framework.FilterSet):
    '''客管数据推送记录'''

    push_status = django_filters.BaseInFilter(field_name='push_status', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='cashactivitydata__cash_activity_id', lookup_expr='in')
    push_time_begin = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='gte')
    push_time_end = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='lte')

    class Meta:
        model = CashActivityDataKeguan
        fields = ('push_status', 'activity_id', 'push_time_begin', 'push_time_end')


class CashActivityLevelRecordFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    cash_activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')
    cash_activity_level_id = django_filters.BaseInFilter(field_name='activity_level_id', lookup_expr='in')
    operation_type = django_filters.BaseInFilter(field_name='operation_type', lookup_expr='in')

    class Meta:
        model = CashActivityLevelRecord
        fields = ('create_time_begin', 'create_time_end', 'cash_activity_id', 'cash_activity_level_id', 'operation_type')